import wxPayUtil from "../../../wxpay/wxPayUtil";
var e = getApp(), t = e.requirejs("core"), a = e.requirejs("jquery");

Page({
    data: {
        disabled: !0,
      logid: 0,
        coupon: {
            count: 0
        }
    },
    onLoad: function(t) {
        e.url(t), this.get_list();
    },
    onShow: function() {
        var t = e.getCache("coupon");
        this.setData({
            "coupon.id": t.id,
            "coupon.name": t.name || ""
        });

      //个人支付完成返回，开始处理数据
    if (e.globalData.orderNo != null && e.globalData.payStatus) {
        let orderno = e.globalData.orderNo;
        //成功业务处理
      var t = e.requirejs("core");
        t.post("member/recharge/wechat_complete", {
          logid: this.logid
        }, function (e) {
          console.log('wechat_complete',e);
          // 0 == e.error ? wx.navigateBack() : t.alert(e.message);
          wx.navigateBack()
        })
      }

    },
    get_list: function() {
        var e = this;
        t.get("member/recharge", {}, function(t) {
          console.log('recharge', t);
            t.show = !0, e.setData(t);
            // e.setData({
            //   money: t.level.monthmoney * 12
            // })
        });
    },
    toggle: function(e) {
        var a = t.pdata(e), i = a.id, o = a.type, n = {};
        n[o] = 0 == i || void 0 === i ? 1 : 0, this.setData(n);
    },
    money: function(e) {
        var i = !0, o = a.trim(e.detail.value), n = this;
        o >= this.data.minimumcharge && (i = !1), t.get("sale/coupon/query", {
            type: 1,
            money: o
        }, function(e) {
            n.setData({
                money: o,
                disabled: i,
                coupon: {
                    id: 0,
                    name: "",
                    count: e.count
                }
            });
        });
    },
  submit: function () {
    var aa = this;
    console.log("data", this.data);
        var e = a.toFixed(this.data.money, 2), i = {};
        this.data.disabled || (void 0 === e || isNaN(e) ? t.alert("请填写正确的充值金额!") : e <= 0 || this.data.disabled ? t.alert("最低充值金额为" + this.data.minimumcharge + "元!") : (i.money = e, 
        i.type = "wechat", i.couponid = this.data.coupon.id, t.post("member/recharge/submit", i, function(e) {
          console.log("member/recharge/submit",e);
          aa.setData({
            "logid": e.logid
          });

          //瞰云支付
          if ("wechat" == i.type) {
            var app = getApp();
            let out_trade_no = e.order.tid; //订单号
            let total_fee = e.order.fee; //支付金额 单位：元
            let body = e.order.title; //商品简称
            let notify_url = app.globalData.approot + 'payment/wechat/kanyun_notify.php'; //回调地址
            let attach = app.globalData.uniacid + ":15"; // uniacid : 类型 。 14为小程序订单 15充值 具体见notify.php中定义
            let title = e.sysset.shopname//收银台标题
            let mchid = e.sysset.wxpay.mchid; //支付商户号
            let apikey = e.sysset.wxpay.apikey; //支付密钥
            wxPayUtil.toPay(mchid, apikey, out_trade_no, total_fee, body, notify_url, attach, title, (response) => {
              console.log(response);
            });
            return;
          }
      //瞰云支付 end
      //以下是原来的代码

            // 0 == e.error ? e.wechat.success ? t.pay(e.wechat.payinfo, function(a) {
            //     "requestPayment:ok" == a.errMsg && t.post("member/recharge/wechat_complete", {
            //         logid: e.logid
            //     }, function(e) {
            //         0 == e.error ? wx.navigateBack() : t.alert(e.message);
            //     }, !0);
            // }) : t.alert(list.wechat.payinfo.message + "\n不能使用微信支付!") : t.alert(e.message);


        }, !0)));
    }
});